package com.yjhh.chdataservice.controller;

import com.yjhh.chdataservice.beans.CommonNameValueVo;
import com.yjhh.chdataservice.beans.ObjMoveSimpleInfoVo;
import com.yjhh.chdataservice.beans.PlacementPointBaseInfoVo;
import com.yjhh.chdataservice.beans.PlacementPointSimpleBaseInfoVo;
import com.yjhh.chdataservice.except.YJHHException;
import com.yjhh.chdataservice.service.FZJCKeyInfoService;
import com.yjhh.chdataservice.service.FZJCObjService;
import com.yjhh.chdataservice.service.FZJCPlacementPointService;
import com.yjhh.chdataservice.util.CommonResultData;
import io.swagger.annotations.*;
import lombok.extern.log4j.Log4j;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * Created by hlantian on 2017/9/26.
 */
@Api(tags = "公开查询系统相关接口")
@RestController
@RequestMapping(value = "/service/public/search")
@Log4j2
public class PublicSearchController {

    @Autowired
    private FZJCObjService fzjcService;
    
    @Autowired
    private FZJCPlacementPointService fzjcPlacementPointService;

    @Autowired
    private FZJCKeyInfoService fzjcKeyInfoService;


    @ApiOperation(value = "根据贫困户身份证号返回贫困户的特定属性信息", notes = "根据贫困户身份证号返回贫困户的特定属性信息")
    @ApiImplicitParam(name = "idCard", value = "贫困户身份证号", required = true, paramType = "query", dataType = "String", defaultValue =
            "612501197312271397")
    @ApiResponses({@ApiResponse(code = 200, message = "请求成功")})
    @RequestMapping(value = "/getPoorObjInfoByIdCard", method = RequestMethod.GET)
    public CommonResultData<ObjMoveSimpleInfoVo> getPoorObjInfoByIdCard(@RequestParam String idCard) {
        CommonResultData<ObjMoveSimpleInfoVo> moveTopByAreaCode = null;
        try {
            long startTime = System.currentTimeMillis();         // 开始时间
            moveTopByAreaCode = fzjcService.getPoorObjInfoByIdCard(idCard);
            moveTopByAreaCode.setRespTime(System.currentTimeMillis() - startTime);
        } catch (YJHHException e) {
            log.warn("getPoorObjInfoByIdCard", e);
            moveTopByAreaCode = new CommonResultData<>(HttpStatus.OK.value(), "no data");
        }
        return moveTopByAreaCode;
    }
    
    
    @ApiOperation(value = "根据安置点名称获取安置基础信息", notes = "根据安置点名称获取安置基础信息")
    @ApiImplicitParam(name = "pointName", value = "安置点名称", required = true, paramType = "query", dataType = "String", defaultValue = "子午镇马家庄安置点")
    @ApiResponses({@ApiResponse(code = 200, message = "请求成功")})
    @RequestMapping(value = "/getPlacementPointDetailByPointName", method = RequestMethod.GET)
    public CommonResultData<PlacementPointSimpleBaseInfoVo> getPlacementPointDetailByPointName(@RequestParam String pointName) {
        CommonResultData<PlacementPointSimpleBaseInfoVo> pointListResult = null;
        try {
            long startTime = System.currentTimeMillis();         // 开始时间
            pointListResult = fzjcPlacementPointService.getPlacementPointDetailByPointName(pointName);
            pointListResult.setRespTime(System.currentTimeMillis() - startTime);
        } catch (YJHHException e) {
            log.warn("getPlacementPointDetailByPointName", e);
            pointListResult = new CommonResultData<>(HttpStatus.OK.value(), "no data");
        }
        return pointListResult;
    }
    
    @ApiOperation(value = "模糊匹配安置点名称获取安置点前十名名称", notes = "模糊匹配安置点名称获取安置点前十名名称")
    @ApiImplicitParam(name = "pointName", value = "安置点名称", required = true, paramType = "query", dataType = "String", defaultValue = "子午")
    @ApiResponses({@ApiResponse(code = 200, message = "请求成功")})
    @RequestMapping(value = "/getPlacementPointListByPointName", method = RequestMethod.GET)
    public CommonResultData<List<PlacementPointBaseInfoVo>> getPlacementPointListByPointName(@RequestParam String pointName) {
        CommonResultData<List<PlacementPointBaseInfoVo>> pointListResult = null;
        try {
            long startTime = System.currentTimeMillis();         // 开始时间
            pointListResult = fzjcPlacementPointService.getPlacementPointListByPointName(pointName);
            pointListResult.setRespTime(System.currentTimeMillis() - startTime);
        } catch (YJHHException e) {
            log.warn("getPlacementPointListByPointName", e);
            pointListResult = new CommonResultData<>(HttpStatus.OK.value(), "no data");
        }
        return pointListResult;
    }
    
    @ApiOperation(value = "获取所有安置基础信息列表", notes = "获取所有安置基础信息列表")
    @ApiResponses({@ApiResponse(code = 200, message = "请求成功")})
    @RequestMapping(value = "/getAllPlacementPointList", method = RequestMethod.GET)
    public CommonResultData<List<PlacementPointSimpleBaseInfoVo>> getAllPlacementPointList() {
        CommonResultData<List<PlacementPointSimpleBaseInfoVo>> pointListResult = null;
        try {
            long startTime = System.currentTimeMillis();         // 开始时间
            pointListResult = fzjcPlacementPointService.getAllPlacementPointList();
            pointListResult.setRespTime(System.currentTimeMillis() - startTime);
        } catch (YJHHException e) {
            log.warn("getAllPlacementPointList", e);
            pointListResult = new CommonResultData<>(HttpStatus.OK.value(), "no data");
        }
        return pointListResult;
    }

    @ApiOperation(value = "获取各地市开工率;竣工率;入住率;集中安置率", notes = "获取各地市开工率;竣工率;入住率;集中安置率")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "areaCode", value = "行政区划编码", required = true, paramType = "query", dataType = "String", defaultValue =
                    "610000000000")
    })
    @ApiResponses({@ApiResponse(code = 200, message = "请求成功")})
    @RequestMapping(value = "/getReportKeyRate", method = RequestMethod.GET)
    public CommonResultData<List<Map<String,Object>>> getReportKeyRate(@RequestParam String areaCode) {
        CommonResultData<List<Map<String,Object>>> statisticalData = null;
        try {
            long startTime = System.currentTimeMillis();         // 开始时间
            statisticalData = fzjcKeyInfoService.getReportKeyRate(areaCode);
            statisticalData.setRespTime(System.currentTimeMillis() - startTime);
        } catch (YJHHException e) {
            log.warn("getReportKeyRate", e);
            statisticalData = new CommonResultData<>(HttpStatus.OK.value(), "no data");
        }
        return statisticalData;
    }

}
